/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
bool fun2(ListNode* head,TreeNode* node)
{
    if(head == nullptr) return true;
    if(node == nullptr) return false;
    if(head->val != node -> val) return false;
    return fun2(head->next,node->left) | fun2(head->next,node->right);
}
bool fun(ListNode* head,TreeNode* node){
    if(node == nullptr)
    {
        return false;
    }
    if(fun2(head,node)){
        return true;
    }
    return fun(head,node->left) | fun(head,node->right);
}
class Solution {
public:
    bool isSubPath(ListNode* head, TreeNode* root) {
        return fun(head,root);
    }
};